import { ref } from "vue";

function useDownCount(initCount: number) {
  const count = ref(0);
  let timer: number | null = null;

  function start() {
    console.log("获取验证码");
    count.value = initCount;
    timer = window.setInterval(() => {
      count.value--;
      if (count.value <= 0 && timer) window.clearInterval(timer);
    }, 1000);
  }

  return { count, start };
}

export default useDownCount;
